package org.fh.util;

import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
 * 说明：路径工具类
 * 作者：cd
 * 
 */
public class PathUtil {
	/**获取Projectpath
	 * @return
	 */
	public static String getProjectpath(){
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		String path = request.getServletContext().getRealPath("/").replaceAll("%20", " ").replaceAll("file:/", "").trim();
		return path;
	}

	/**获取Classpath
	 * @return
	 */
	public static String getClasspath(){
		String path =  (String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))).replaceAll("file:/", "").replaceAll("%20", " ").trim();	
		if(path.indexOf(":") != 1){
			path = File.separator + path;
		
		}
//		path = "/home/moa/";  //正式环境
//		path="E:\\moa\\";
		return path;
	}
	
	/**获取根目录
	 * @return
	 */
	public static String getHttpUrlpath(HttpServletRequest request){
		//String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/".trim();
//		String path = request.getScheme()+"://"+request.getServerName()+":8080/".trim();  //测试环境
		String path = "http://"+request.getServerName()+":8080/".trim();  //测试环境
//		String path = request.getScheme()+"://"+request.getServerName()+"/".trim();   //正式环境
		return path;
	}

	/**上传路径
	 * @return
	 */
	public static String getHttpUrlpathFile(){
		//String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/".trim();
		String path = "E:\\apache-tomcat-8.5.60\\webapps\\".trim();     //本机地址
//		String path ="/baidumap/apache-tomcat-8.5.60/webapps/".trim();  //服务器地址
		return path;
	}
}
